package com.lw.lost.daos

import android.content.ContentValues
import android.database.Cursor
import android.database.sqlite.SQLiteDatabase

class MatchConditionDao(private val db: SQLiteDatabase) {
    
    fun insert(userId: Long, interestId: Long, preferGender: Int, minAge: Int, maxAge: Int): Long {
        val values = ContentValues().apply {
            put("userId", userId)
            put("interestId", interestId)
            put("preferGender", preferGender)
            put("minAge", minAge)
            put("maxAge", maxAge)
        }
        return db.insert("match_conditions", null, values)
    }

    fun getMatchConditionsByUserId(userId: Long): Cursor {
        return db.query(
            "match_conditions",
            null,
            "userId = ?",
            arrayOf(userId.toString()),
            null,
            null,
            null
        )
    }

    fun findMatches(gender: Int, age: Int): Cursor {
        return db.rawQuery(
            """
            SELECT mc.* FROM match_conditions mc
            WHERE mc.preferGender IN (?, 2)
            AND ? BETWEEN mc.minAge AND mc.maxAge
            """,
            arrayOf(gender.toString(), age.toString())
        )
    }
} 